package com.tm.biz.service.impl;

import com.tm.biz.feignclient.OrderClient;
import com.tm.biz.feignclient.StorageClient;
import com.tm.biz.service.BizService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class BizServiceImpl implements BizService {

    private final StorageClient storageClient;

    private final OrderClient orderClient;

    public BizServiceImpl(StorageClient storageClient, OrderClient orderClient) {
        this.storageClient = storageClient;
        this.orderClient = orderClient;
    }

    public void createOrders(Map<String, String> map) {
        Map<String,String> orderMap = new HashMap<String, String>();
        orderMap.put("userId",map.get("userId"));
        orderMap.put("productId",map.get("productId"));
        orderMap.put("money","250");
        orderClient.createOrder(orderMap);
        Map<String,String> storageMap = new HashMap<String, String>();
        storageMap.put("id",map.get("productId"));
        storageMap.put("total","200");
        storageMap.put("used","10");
        storageClient.updateStorage(storageMap);
    }
}
